package com.woniuxy.microsportsserver.weightmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.common.bean.PageDto;
import com.woniuxy.microsportsserver.bean.WeightAnalysisInfo;
import com.woniuxy.microsportsserver.bean.WeightInfo;
import com.woniuxy.microsportsserver.weightmag.mapper.WeightMapper;
import com.woniuxy.microsportsserver.weightmag.service.IWeightService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WeightServiceImpl implements IWeightService {
    @Resource
    private WeightMapper weightMapper;

    @Override
    public PageDto findAll(WeightInfo weightInfo ,Integer pageNum,Integer pageSize) {
//        return weightMapper.findAll(weightInfo);
        if(pageNum<=0){
            return null;
        }
        PageHelper.startPage(pageNum, pageSize);
        List<WeightInfo> data = weightMapper.findAll(weightInfo);
        PageInfo<WeightInfo> pageInfo = new PageInfo<>(data);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(pageInfo.getTotal());
        pageDto.setData(data);
        return pageDto;
    }

    @Override
    public WeightInfo findOneByUserId(WeightInfo weightInfo) {
        return weightMapper.findOneByUserId(weightInfo.getUserId());
    }
    //各年龄段平均体重
    @Override
    public List<WeightAnalysisInfo> findWeightByAgeType() { return weightMapper.findWeightByAgeType();
    }

    @Override
    public List<WeightAnalysisInfo> WeightPercentage() {
        return weightMapper.WeightPercentage();
    }
}
